#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;



vector <int> all;

void load()
{

	{
	for (int i = 1; i <= 6; i++)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			int num = 0;
			for (int k = 0; k < i; k++)
			{
				if (j & (1 << k))
					num = num * 10 + 4;
				else num = num * 10 + 7;
			}
			if (num <= 10000)
				all.pb(num);
		}
	}
	sort(all.begin(), all.end());
	}
	cerr << all.size();
}

int a[123123];
int l[123123];
int r[123123];
int type[123123];

class Event
{
	public:
		int l, r, d;
		Event(){}
		Event(int l ,int r, int d) : l(l), r(r), d(d){}
};

inline bool operator < (const Event &e1, const Event &e2)
{
	return e1.l < e2.l || e1.l == e2.l && e1.d > e2.d;
}

prioriy_queue <pair <int, int> > heap;
int size;
int tree[123123];
vector <int> happy[123123];
int added[123123];

void add(int val)
{
	int i = size;
	added[size++] = val
	while (i < 100000)
	{
		tree[i] += val;
		i |= (i + 1);
	}
}

void erase(int pos)
{
	int val = added[pos];
	int i = pos;
	while (i < 100000)
	{
		tree[i] -= val;
		i |= i + 1;
	}
}

int getsum(int pos)
{
	int res = 0;
	while (pos >= 0)
	{
		res += tree[pos];
		pos -= (pos & ~(pos + 1)) + 1;
	}
	return res;
}

bool findsum(int sum)
{
	int l = 0;
	int r = size - 1;
	int mid, t;
	while (l <= r)
	{
		mid = (l + r) >> 1;
		t = getsum(mid);
		if (t == sum)
			return true;
		else if (t < sum)
			l = mid + 1;
		else r = mid - 1;
	}
	return false;

}

void solve()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	nextLine();
	for (int i = 0; i < m; i++)
	{
		c = getchar();
		if (c == 'a')
		{
			getchar(); getchar();
			type[i] = 0;
			scanf ("%d%d%d", &l[i], &r[i], &d[i]);
			events.pb(Event(l[i], r[i], d[i]));
		}                          
		else
		{
			getchar();getchar();
			getchar();getchar();
			scanf("%d%d", &l[i], &r[i]);
			type[i] = 1;
			//events.pb(Event(l[i], r[i], 0));
		}
		nextLine();
	}
	sort(events.begin(), events.end());
	int pos = 0;
	int t;
	for (int i = 0; i < n; i++)
	{
		while (pos < events.size() && events[pos].l < i)
		{
			add(events[pos].d);
			heap.insert(mp(events[pos].r, size - 1));
		}
		while (!heap.empty() && heap.top().ff < i)
		{
			erase(heap.top().ss);
			heap.pop();
		}
		for (int j = 0; j < all.size(); j++)
		{
			if (a[i] > all[j]) continue;
			t = findsum(all[j] - a[i]);
			if (t != -1)
				happy[i].pb(t);
		}
	}

}

#define file "e"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}

